module time_mod

	implicit none

	private
	public time_init
	public time_advance
	public time_step
	public old_time_idx
	public new_time_idx
	public elapsed_seconds

	real(8) elapsed_seconds
	integer time_step
	integer old_time_idx
	integer new_time_idx

contains
	
	subroutine time_init()

		time_step = 0
		elapsed_seconds = 0
		old_time_idx = 1
		new_time_idx = 2

	end subroutine time_init

	subroutine time_advance(dt_in_seconds)

		real(8), intent(in), optional :: dt_in_seconds

		call time_swap_indices(old_time_idx, new_time_idx)

		time_step = time_step + 1

		elapsed_seconds = elapsed_seconds + dt_in_seconds

	end subroutine time_advance

	subroutine time_swap_indices(i, j)

		integer, intent(inout) :: i
		integer, intent(inout) :: j

		integer tmp

		tmp = i
		i = j
		j = tmp

	end subroutine time_swap_indices

end module time_mod